import axios from "axios";

const server = axios.create({
  withCredentials: true,
  timeout: 3000,
})

server.interceptors.request.use(
  (config) => {
    var userInfo = localStorage.getItem("userInfo");
    // 向请求头中塞入 token
    config.headers["x-litemall-token"] = userInfo ? JSON.parse(userInfo).token : "";
    return config;
  },(err) => Promise.reject(err)
)

server.interceptors.response.use(
  (response) => {
    return response.data;
  },(err) => Promise.reject(err)
)


export default server